import { configureStore } from '@reduxjs/toolkit'
import {
  useSelector,
  useDispatch,
  TypedUseSelectorHook,
  shallowEqual
} from 'react-redux'

import recommendReducer from '@/views/discover/c-views/recommend/store/recommend'
import playerReducer from '@/views/player/store/player'

const store = configureStore({
  reducer: {
    // 添加reducer
    recommend: recommendReducer,
    player: playerReducer
  }
})

type GetStateFnType = typeof store.getState
// 获取store中的state类型
export type IRootStateType = ReturnType<GetStateFnType>

// useAppSelector的hook
export const useAppSelector: TypedUseSelectorHook<IRootStateType> = useSelector
type DispatchType = typeof store.dispatch
export const useAppDispatch: () => DispatchType = useDispatch
export const shallowEqualApp = shallowEqual

export default store
